package mc747.portal.logicas;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ActionWebService.Hello_messageHelloMessagePort;
import DefaultNamespace.LogisticaEntrega;

import mc747.portal.servlet.Logica;
import mc747.servicos.atendcliente.AtendClienteFactory;
import mc747.servicos.logistica.LogisticaFactory;

public class Rastreio implements Logica {

	@Override
	public void executa(HttpServletRequest req, HttpServletResponse res)
			throws Exception {

		LogisticaEntrega logistica = new LogisticaFactory().Logistica();
		
		RequestDispatcher rd;
		
		String resp = req.getParameter("codigo");
		
		if (resp.matches("^[0-9]*$"))
			resp = logistica.verificaSituacaoEntrega(Integer.parseInt(resp));
		else
			resp = logistica.verificaSituacaoEntrega(0);
		
		if (resp.substring(0, 1).equals("OK")) 
			req.setAttribute("erro", resp.substring(3));
		else
			req.setAttribute("erro", resp.substring(4));
			
		rd = req.getRequestDispatcher(req
			.getParameter("fwdSuccess"));
	
		rd.forward(req, res);
	}

}
